package cn.zhz.privacy.config;

import cn.zhz.privacy.crypto.AesCrypto;
import cn.zhz.privacy.handler.CryptHandler;
import cn.zhz.privacy.handler.DesensitizeHandler;
import cn.zhz.privacy.handler.IEncryptDataHandler;
import cn.zhz.privacy.interceptor.CommonInnerInterceptor;
import cn.zhz.privacy.interceptor.MybatisEncryptInterceptor;
import cn.zhz.privacy.properties.CryptoProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @author ZHZ
 * @date 2021-11-17
 * @apiNote
 */
@Configuration
@EnableConfigurationProperties(CryptoProperties.class)
public class MybatisEncryptAutoConfiguration {

    @Bean
    public MybatisEncryptInterceptor encryptInterceptor() {
        return new MybatisEncryptInterceptor();
    }

    /**
     * 脱敏处理器
     * @return
     */
    @Bean
    public DesensitizeHandler desensitizeHandler() {
        return new DesensitizeHandler();
    }

    /**
     * 加密处理器
     * @param cryptoProperties
     * @return
     */
    @Bean
    public CryptHandler cryptHandler(CryptoProperties cryptoProperties) {
        return new CryptHandler(cryptoProperties);
    }

    @Bean
    public CommonInnerInterceptor commonInnerInterceptor(List<IEncryptDataHandler> handlerList) {
        return new CommonInnerInterceptor(handlerList);
    }

//    @Bean
//    public DesensitizeInterceptor desensitizeInterceptor(DesensitizeHandler desensitizeHandler) {
//        return new DesensitizeInterceptor(desensitizeHandler);
//    }

    @Bean
    public AesCrypto defaultCrypto() {
        return new AesCrypto();
    }

}
